 
#ifndef		FITTED_VI_SOLVER
#define		FITTED_VI_SOLVER

#include "KDTree.h"
#include "MDPSolver.h"
#include <ANN/ANN.h>
#include "MatlabMatrix.h"
#include <list>
using namespace std; 

class KDTreeLearner; 


class FittedVISolver
	:public MDPSolver
{
public: 
	FittedVISolver(MREAgent* a, TFGenerator* tf, RFGeneralizer* rf); 
	~FittedVISolver(); 
	void generateUniformSamples(list< std::pair<Observation,double> >& l, int sampleSize);

	virtual Action getBestAction(Observation state);
	virtual void	solveModel(Observation currentState); 
	virtual double getStateValue(const Observation state){ return getStateValue(state,0); } 
	virtual void operator()(); 

	double getStateValue(const Observation state, int horizon);		//returns the value of a state
	double getQValue(Observation state, Action a, int horizon=1);	//returns the qvalue (it considers this: q(s,a) = \gamma* V(T(s,a))

protected:
	Observation getNextItem(Observation st, int n);
	void clearSamples(); 
public:

	static int K; 
	int sampleSize;									//how many samples are we solving for 

	ANNpointArray samples; 
	//for each state/action, we store the information about the next state's neighbors in the next two variables: 
	MatlabMatrix<ANNidx*> nnIdx;									//this is a place to put the indexes of the k nearest neighbors
	MatlabMatrix<ANNdist*> dists;									//this is a place to put the distances of the k nn
	double* values; 
};

#endif
